<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>{{ i18n('course.unit.point.view') }}</div>
        </div>

        <div class="admin_main_block_right">
          <div class="mr10">
            <el-button icon="Back" @click="router.push({name: 'module_education_course_unit_point_list', query: {course_id: dataForm.course_id, unit_id: dataForm.unit_id}})">
              {{ i18n('common.return') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_form_main">
        <el-form ref="formRef" :model="dataForm" label-width="100">
          <el-card class="box-card" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('course.basic_info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-row>
                <el-col :span="4">
                  <el-image :src="dataForm.picture"></el-image>
                </el-col>
                <el-col :span="20">
                  <el-descriptions border>
                    <!-- 第一行 -->
                    <el-descriptions-item width="200" :label="i18n('course.unit.point.title')" label-align="right">
                      {{ dataForm.title }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('course.title')" label-align="right">
                      {{ dataForm.course_title }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('course.unit.point.course_unit')" label-align="right">
                      {{ dataForm.complete_name }}
                    </el-descriptions-item>

                    <!-- 第二行 -->
                    <el-descriptions-item width="200" :label="i18n('course.unit.point.type')" label-align="right" :span="3">
                      {{ dataForm.type }}
                    </el-descriptions-item>

                    <!-- 第三行 -->
                    <el-descriptions-item width="200" :label="i18n('course.unit.point.time_length')" label-align="right">
                      {{ dataForm.statistical.point_time_length }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('course.unit.point.study_total')" label-align="right">
                      {{ dataForm.statistical.study_total }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('course.unit.point.study_finish_total')" label-align="right">
                      {{ dataForm.statistical.study_finish_total }}
                    </el-descriptions-item>

                    <!-- 第五行 -->
                    <el-descriptions-item width="200" :label="i18n('course.unit.point.description')" label-align="right" :span="3">
                      {{ dataForm.description }}
                    </el-descriptions-item>

                    <!-- 第六行 -->
                    <el-descriptions-item width="200" :label="i18n('course.unit.point.content')" label-align="right" :span="3">
                      <div v-html="dataForm.content"></div>
                    </el-descriptions-item>

                    <!-- 第七行 -->
                    <el-descriptions-item width="200" :label="i18n('common.sort')" label-align="right" :span="3">
                      {{ dataForm.sort }}
                    </el-descriptions-item>

                    <!-- 第八行 -->
                    <el-descriptions-item width="200" :label="i18n('course.is_hidden')" label-align="right">
                      {{ dataForm.is_hidden }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('course.status')" label-align="right" :span="2">
                      {{ dataForm.status }}
                    </el-descriptions-item>
                  </el-descriptions>
                </el-col>
              </el-row>
            </div>
          </el-card>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script setup name="course-unit-point-view">
  import { useBase } from "@/hooks/base/useBase"
  import { useForm } from "@/hooks/form/useForm"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('education/course/unit/point')

  const dataForm = reactive({
    id: 0,
    course_id: 0,
    unit_id: 0,
    course_title: '',
    picture: '',
    type: 1,
    title: '',
    complete_name: '',
    description: '',
    sort: 0,
    is_hidden: '',
    status: '',
    statistical: []
  })

  const { formRef } = useForm(model.value, dataForm)

  const init = (form) => {
    dataForm.id = query.id || 0

    nextTick(() => {
      form.value.resetFields()
      if (dataForm.id) {
        $http({
          url: $http.adornUrl(`/${model.value}/view/${dataForm.id}`),
          method: 'get',
          params: $http.adornParams({}),
        }).then(({ data }) => {
          if (data && data.status === 200) {
            dataForm.course_title = data.data.course.title
            dataForm.picture = data.data.picture
            dataForm.type = data.data.type.text
            dataForm.title = data.data.title
            dataForm.complete_name = data.data.complete_name
            dataForm.description = data.data.description
            dataForm.sort = data.data.sort
            dataForm.is_hidden = data.data.is_hidden.text
            dataForm.status = data.data.status.text
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/statistical/data`),
              method: 'get',
              params: $http.adornParams({
                'course_id': dataForm.course_id,
                'unit_id': dataForm.unit_id,
                'point_id': dataForm.id,
              }),
            }).then(({ data }) => {
              if (data && data.status === 200) {
                dataForm.statistical = data.data
              }
            })
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/detail/data`),
              method: 'get',
              params: $http.adornParams({
                'course_id': dataForm.course_id,
                'unit_id': dataForm.unit_id,
                'point_id': dataForm.id,
              }),
            }).then(({ data }) => {
              if (data && data.status === 200) {
                dataForm.content = data.data.content
              }
            })
          }
        })
      }
    })
  }

  onMounted(() => {
    dataForm.course_id = query.course_id
    dataForm.unit_id = query.unit_id

    init(formRef)
  })
</script>

<style lang="scss" scoped>
  .el-image {
    padding: 0 5px;
    max-width: 260px;
    max-height: 260px;
    width: 100%;
    height: 260px;
  }
  .form-width-textarea-100 {
    width: 100%;
  }
</style>
